import request from "@/utils/request"
import { UserLoginResponseData, LoginParams, WXLoginResponseData, VisitorResponseData, submitOrderParams, submitOrderResponseData, OrderInfoResponseData, QrCodeResponseData, PayStatusResponseData, UserInfoResponseData, AuthParams, OrderListResponseData, OrderStatusResponseData, patientParams, patientResponseData } from "./type"

export const loginAPI = (data: LoginParams) => {
    return request<any, UserLoginResponseData>({
        url: '/user/login',
        method: 'post',
        data: data
    })
}

export const getWechatLogin = (wxRedirectUri: string) => {
    return request<any, WXLoginResponseData>({
        url: `/user/weixin/getLoginParam?wxRedirectUri=${wxRedirectUri}`
    })
}

export const getUserAPI = () => {
    return request<any, VisitorResponseData>({
        url: '/user/patient/auth/findAll'
    })
}

export const submitOrderAPI = (params: submitOrderParams) => {
    return request<any, submitOrderResponseData>({
        url: `/order/orderInfo/auth/submitOrder/${params.hoscode}/${params.scheduleId}/${params.patientId}`,
        method: 'post'
    })
}

export const getOrderDetailAPI = (id: string) => {
    return request<any, OrderInfoResponseData>({
        url: `/order/orderInfo/auth/getOrderInfo/${id}`
    })
}

export const cancleRegisterAPI = (orderId: string) => {
    return request<any, any>({
        url: `/order/orderInfo/auth/cancelOrder/${orderId}`
    })
}

export const getQRCODEAPI = (orderId: string) => {
    return request<any, QrCodeResponseData>({
        url: `/order/weixin/createNative/${orderId}`
    })
}

export const getPayResultAPI = (id: string) => {
    return request<any, PayStatusResponseData>({
        url: `/order/weixin/queryPayStatus/${id}`
    })
}

export const getUserInfoAPI = () => {
    return request<any, UserInfoResponseData>({
        url: '/user/auth/getUserInfo'
    })
}

export const getUserAuthAPI = (params: AuthParams) => {
    return request<any, any>({
        url: '/user/auth/userAuah',
        method: 'post',
        data: params
    })
}

export const getUserOrderInfoAPI = (page: number, limit: number, patientId?: string, orderStatus?: string) => {
    return request<any, OrderListResponseData>({
        url: `/order/orderInfo/auth/${page}/${limit}?patientId=${patientId}&orderStatus=${orderStatus}`
    })
}

export const getOrderListAPI = () => {
    return request<any, OrderStatusResponseData>({
        url: '/order/orderInfo/auth/getStatusList'
    })
}

export const getCityAPI = (parentId: string) => {
    return request<any, any>({
        url: `/cmn/dict/findByParentId/${parentId}`
    })
}

export const addORUpdatePatientAPI = (data: patientParams) => {
    if (data.id) {
        return request<any, any>({
            url: `/user/patient/auth/update`,
            method: 'put',
            data
        })
    } else {
        return request<any, any>({
            url: `/user/patient/auth/save`,
            method: 'post',
            data
        })
    }
}

export const getPatientByIdAPI = (id: string) => {
    return request<any, patientResponseData>({
        url: `/user/patient/auth/get/${id}`
    })
}

export const deletePatientAPI = (id: string) => {
    return request({
        url: `/user/patient/auth/remove/${id}`,
        method: 'delete'
    })
}